let crypto = require('crypto');
function encrypt(data, key, iv) {
    let cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
    cipher.update(data);
    return cipher.final('hex');//16进制的意思，把结果输出成16进制的字符串
}
function decrypt(data, key, iv) {
    let cipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
    cipher.update(data, 'hex');//添加hex也就是十六进制的字符串数据
    return cipher.final('utf8');//输出成utf8字符串
}
let key = '1234567890123456';
let iv = '1234567890123456';
let data = 'hello';
let encryptedData = encrypt(data, key, iv);
console.log(encryptedData);
let decryptedData = decrypt(encryptedData, key, iv);
console.log(decryptedData);



